package com.aididi.controller;

import com.aididi.service.ConsumerFeignService;
import com.aididi.service.TestService;
import io.seata.core.context.RootContext;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Auther: zx.xu
 * @Description:
 */
@Slf4j
@RestController
public class ConsumerFeignController {

    @Autowired
    private ConsumerFeignService consumerFeignService;

    @Autowired
    private TestService testService;

    @Value("${spring.application.name}")
    String serverName;


    /**
     * feign服务
     * @return  @GlobalTransactional  name属性：全局事务实例名称，随意写不重复就行
     */
    @GetMapping("/test/hello")
    @GlobalTransactional(name="myglobal",rollbackFor = Exception.class)
    public String test(){
        log.info("ORDER XID is: {}", RootContext.getXID());
        return consumerFeignService.test(serverName);
    }


    /**
     * sentinel测试方法
     * @param name
     * @return
     */
    @GetMapping(value = "/hello/{name}")
    public String hi(@RequestParam(value = "name",defaultValue = "forezp",required = false)String name){
        return testService.sayHello(name);
    }




}
